package com.sdo.bambooksdk;

import com.sun.jna.ptr.IntByReference;
import java.io.File;

public class BBUtil {

    public static int getConn() {
        String lpszIP = "192.168.250.2";
        int timeOut = 0;
        IntByReference hConn = new IntByReference();
        int expResult = Const.BR_SUCC;
        int result = BambookCore.INSTANCE.BambookConnect(lpszIP, timeOut, hConn);
        if (expResult == result) {
            return hConn.getValue();
        } else {
            return 0;
        }

    }

    public static void deleteDir(String filepath) {
        File f = new File(filepath);
        if (f.exists() && f.isDirectory()) {
            if (f.listFiles().length == 0) {
                f.delete();
            } else {
                File delFile[] = f.listFiles();
                int i = f.listFiles().length;
                for (int j = 0; j < i; j++) {
                    if (delFile[j].isDirectory()) {
                        deleteDir(delFile[j].getAbsolutePath());
                    }
                    delFile[j].delete();
                }
            }
        }
    }

    public static void cleanFiles(String file, String path) {
        (new File(file)).deleteOnExit();
        deleteDir(path);
    }
}
